# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _

from subprocess import call
import sys

class res_company(osv.osv):
    _inherit = "res.company"

    _columns = {
        'url': fields.char('File URL', size=1024),
        'url2': fields.char('File CSV URL', size=1024),
        'datas_fname': fields.char('File Name',size=256),
    }

    def test_path(self, cr, uid, ids, context=None):
        for comp in self.browse(cr, uid, ids, context=context):
            try:
                file_path = comp.url or ''
                file_name = comp.datas_fname or ''
#     
                mdb_path=file_path + file_name
#                 csv_path=file_path + 'output.csv'
#                 conversion_string="mdb-export %s CHECKINOUT | tail -n +2 | cut -d, -f1,2,3 | tr / - >%s"%(mdb_path,csv_path)
#                 print conversion_string
#                 call(conversion_string,shell=True)
#             except RuntimeError:
#                 raise osv.except_osv(_('Error!'),_("wrong File Path or name or permission denied."))
                f = open(mdb_path, 'r')
                s = f.readline()
                raise osv.except_osv(_('Success!'),_("Success"))

#            try:

            except IOError as e:
                raise osv.except_osv(_('Error!'),_("I/O error({0}): {1}".format(e.errno, e.strerror)))
#             except:
#                 raise osv.except_osv(_('Error!'),_("Unexpected error:", sys.exc_info()[0]))
            return True

res_company()


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
